<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<!-- 客户信息-->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="所属行业" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入所属行业查询" v-model="queryParam.industry"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="省份" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!-- <a-input placeholder="请输入省份" v-model="queryParam.province"></a-input> -->
                  <a-select
                    v-model="queryParam.province"
                    allowClear
                    placeholder="请输入省份"
                    showSearch
                    optionFilterProp="children"
                  >
                    <a-select-option v-for="(item, index) in province" :key="index" :value="item">
                      {{ item }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入客户名称" v-model="queryParam.name"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="销售负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入销售负责人" v-model="queryParam.salesDirector"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="录入时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    :placeholder="['开始时间', '结束时间']"
                    v-model="queryParam.createTime"
                    @change="onDateChange"
                    format="YYYY-MM-DD"
                  />
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin: 5px 0px">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button @click="download()" type="primary" icon="download">导出</a-button>
          <!-- <a-upload
            v-if="btnEnableList.indexOf(1) > -1"
            name="file"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="importExcelUrl"
            @change="handleImportExcel"
          >-->
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="{ x: 1600, y: 800 }"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleAddContacts(record)">联系人</a>
              <a-divider type="vertical" />
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="remark" slot-scope="text, record">
              <a-tooltip>
                <template slot="title">
                  {{ record.remark }}
                </template>
                <div>{{ record.remark | ellipsis(10) }}</div>
              </a-tooltip>
            </span>
            <span slot="name" slot-scope="text, record">
              <a-tooltip>
                <template slot="title">
                  {{ record.name }}
                </template>
                <div>{{ record.name | ellipsis(8) }}</div>
              </a-tooltip>
            </span>
            <span slot="addr" slot-scope="text, record">
              <a-tooltip>
                <template slot="title">
                  {{ record.addr }}
                </template>
                <div>{{ record.addr | ellipsis(10) }}</div>
              </a-tooltip>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <customer-modal ref="modalForm" @ok="modalFormOk"></customer-modal>
        <ContactsModal ref="ContactsmodalForm" @ok="modalFormOk"></ContactsModal>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
import CustomerModal from './modules/CustomerModal'
import ContactsModal from './modules/ContactsModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { openDownloadDialog, sheet2blob } from '@/utils/util'
import { downFile } from '@/api/manage'
import JDate from '@/components/jeecg/JDate'
export default {
  name: 'CustomerList',
  mixins: [JeecgListMixin],
  components: {
    CustomerModal,
    ContactsModal,
    JDate
  },
  data() {
    return {
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      //省份--前端写死
      province: [
        '北京市',
        '天津市',
        '上海市',
        '重庆市',
        '河北省',
        '山西省',
        '辽宁省',
        '吉林省',
        '黑龙江省',
        '江苏省',
        '浙江省',
        '安徽省',
        '福建省',
        '江西省',
        '山东省',
        '河南省',
        '湖北省',
        '湖南省',
        '广东省',
        '海南省',
        '四川省',
        '贵州省',
        '云南省',
        '陕西省',
        '甘肃省',
        '青海省',
        '台湾省',
        '香港特别行政区',
        '澳门特别行政区',
        '内蒙古自治区',
        '广西壮族自治区',
        '西藏自治区',
        '宁夏回族自治区',
        '新疆维吾尔自治区'
      ],
      // 查询条件
      queryParam: {
        supplier: '',
        type: '客户',
        telephone: '',
        phonenum: ''
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        { title: '所属行业', dataIndex: 'industry', width: 100, align: 'center' },
        { title: '客户名称', dataIndex: 'name', width: 150, align: 'center', scopedSlots: { customRender: 'name' } },
        { title: '省份', dataIndex: 'province', width: 100, align: 'center' },
        { title: '主要对接人', dataIndex: 'contact', width: 100, align: 'center' },
        { title: '职位', dataIndex: 'work', width: 100, align: 'center' },
        { title: '联系电话', dataIndex: 'phone', width: 150, align: 'center' },
        { title: '客户地址', dataIndex: 'addr', width: 150, align: 'center', scopedSlots: { customRender: 'addr' } },
        { title: '客户规模', dataIndex: 'customerSize', width: 100, align: 'center' },
        { title: '财务状况', dataIndex: 'financialSituation', width: 100, align: 'center' },
        { title: '销售负责人', dataIndex: 'salesDirector', width: 100, align: 'center' },
        { title: '录入时间', dataIndex: 'entryTime', width: 100, align: 'center' },
        { title: '备注', dataIndex: 'remark', width: 140, align: 'center', scopedSlots: { customRender: 'remark' } },
        {
          title: '操作',
          dataIndex: 'action',
          width: 200,
          align: 'center',
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/customerInfo/searchList',
        delete: '/customerInfo/remove',
        deleteBatch: '/supplier/deleteBatch',
        importExcelUrl: '/supplier/importCustomer',
        exportXlsUrl: '/supplier/exportExcel',
        batchSetStatusUrl: '/supplier/batchSetStatus'
      }
    }
  },
  filters: {
    ellipsis(val, length) {
      if (val) {
        if (val.length > length) {
          return val.substring(0, length) + '...'
        } else {
          return val
        }
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  methods: {
    //导出
    download() {
      downFile('/customerInfo/exportExcel').then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), '客户信息')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', '客户信息')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    onDateChange: function(value, dateString) {
      this.queryParam.startTime = dateString[0]
      this.queryParam.endTime = dateString[1]
      console.log(this.queryParam)
    },
    searchReset() {
      this.queryParam = {
        type: '客户'
      }
      this.loadData(1)
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = false
      }
    },
    //添加人
    handleAddContacts(record) {
      this.$refs.ContactsmodalForm.edit(record)
      this.$refs.ContactsmodalForm.title = '联系人'
      this.$refs.ContactsmodalForm.disableSubmit = false
      this.$refs.modalForm.isReadOnly = true
    }
  }
}
</script>
<style scoped>
/** Button按钮间距 */
.table-operator .ant-btn {
  margin: 0 8px 8px 0;
}
@import '~@assets/less/common.less';
</style>
